/**
 * Copyright 2021 xpstem.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.xpstem.lelink.enums;

/**
 * EV3 command reply status.
 * @author billy zhang
 */
public enum ReplyStatus {
    UNKNOWN(                0xFF ),
    SUCCESS(                0x00 ),
    UNKNOWN_HANDLE(         0x01 ),
    HANDLE_NOT_READY(       0x02 ),
    CORRUPT_FILE(           0x03 ),
    NO_HANDLES_AVAILABLE(   0x04 ),
    NO_PERMISSION(          0x05 ),
    ILLEGAL_PATH(           0x06 ),
    FILE_EXITS(             0x07 ),
    END_OF_FILE(            0x08 ),
    SIZE_ERROR(             0x09 ),
    UNKNOWN_ERROR(          0x0A ),
    ILLEGAL_FILENAME(       0x0B ),
    ILLEGAL_CONNECTION(     0x0C );

    private int value;

    private ReplyStatus(int value) {
        this.value = value;
    }

    public int value() {
        return value;
    }

    public static ReplyStatus ofValue(short value) {
        switch (value) {
            case 0x00:
                return SUCCESS;
            case 0x01:
                return UNKNOWN_HANDLE;
            case 0x02:
                return HANDLE_NOT_READY;
            case 0x03:
                return CORRUPT_FILE;
            case 0x04:
                return NO_HANDLES_AVAILABLE;
            case 0x05:
                return NO_PERMISSION;
            case 0x06:
                return ILLEGAL_PATH;
            case 0x07:
                return FILE_EXITS;
            case 0x08:
                return END_OF_FILE;
            case 0x09:
                return SIZE_ERROR;
            case 0x0A:
                return UNKNOWN_ERROR;
            case 0x0B:
                return ILLEGAL_FILENAME;
            case 0x0C:
                return ILLEGAL_CONNECTION;
            default:
                return UNKNOWN;
        }

    }
}
